package com.chushouya.controller.manager.admin;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.manager.dto.admin.dept.DeptListDTO;
import com.chushouya.manager.dto.admin.dept.DeptListQuery;
import com.chushouya.manager.dto.admin.dept.DeptSaveDTO;
import com.chushouya.manager.dto.admin.dept.DeptTreeDTO;
import com.chushouya.manager.service.admin.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = ServiceType.PLATFORM + "部门管理")
@RestController
@RequestMapping(ServiceType.PLATFORM + "/dept")
public class DeptController {

    @Resource
    private DeptService deptService;

    @ApiOperation("获取部门列表")
    @GetMapping("/list")
    public Response<List<DeptListDTO>> list(DeptListQuery query) {
        return Response.success(deptService.selectDeptList(query));
    }

    @ApiOperation("根据部门编号获取详细信息")
    @GetMapping("/getDeptDetail")
    public Response<DeptSaveDTO> getDeptDetail(Long deptId) {
        return Response.success(deptService.getDeptDetail(deptId));
    }

    @ApiOperation("获取部门下拉树列表")
    @GetMapping("/getDeptTree")
    public Response<List<DeptTreeDTO>> getDeptTree() {
        return Response.success(deptService.getDeptTree());
    }

    @ApiOperation("新增部门")
    @Log(businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Response<Long> add(@Validated @RequestBody DeptSaveDTO dept) {
        return Response.success(deptService.addDept(dept));
    }

    @ApiOperation("修改部门")
    @Log(businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Response<Long> edit(@Validated @RequestBody DeptSaveDTO dept) {
        return Response.success(deptService.editDept(dept));
    }

    @ApiOperation("删除部门")
    @Log(businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public Response<Void> remove(Long deptId) {
        deptService.removeDept(deptId);
        return Response.success();
    }
}
